package com.walker.taogong.web;

import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.walker.taogong.bll.UserBll;
import com.walker.taogong.datamodel.User;

public class EditUser
{
    /** Logger. */
    private static Logger log = LoggerFactory.getLogger(EditUser.class);
    
    
    /************************ BLL 服务引用 *******************************************/
    
    private UserBll userBll;
    
    public void setUserBll(UserBll userBll)
    {
        this.userBll= userBll;
    }
    
    /*************************启动测试用************************************/
    /**
     * 组件启动初期化
     */
    protected void activate(ComponentContext cc) throws Exception
    {
        log.info("{} is starting!", cc.getProperties().get("name") );

        //主流程
        
        String email = "zhangsan@test.com";
        
        User user = userBll.getUserByEmail(email);
        
        log.info(user.toString());
        
        //1. 注册用户
        user.setUserName("zhang san hao");
        
        //email或mobile任选其一
        user.setEmail("zhangsan san hao@test.com") ;  //
        user.setMobile("12345678")    ;   //optional
        
        if(userBll.updateUser(user))
        {
            log.info("你已经成功更新数据");
            log.info(user.toString());
        }
        
    }

}
